package cc.z8g.browser.core.config

import android.view.MenuItem
import androidx.annotation.IntDef
import cc.z8g.browser.R

/**
 * Adapts a click on a menu item to a [MenuItems].
 */
object MenuItems {

    const val NEW_INCOGNITO_WINDOW = 2
    const val SHARE = 3
    const val OPEN_HISTORY = 4
    const val OPEN_DOWNLOADS = 5
    const val FIND = 6
    const val COPY_LINK = 7
    const val OPEN_RESOURCES = 8
    const val ADD_BOOKMARK = 9
    const val SETTINGS = 10
    const val BACK = 11
    const val FORWARD = 12

    @Retention(AnnotationRetention.SOURCE)
    @IntDef(value = [NEW_INCOGNITO_WINDOW, SHARE, OPEN_HISTORY, OPEN_DOWNLOADS, OPEN_RESOURCES,
        FIND, COPY_LINK, ADD_BOOKMARK, SETTINGS, BACK, FORWARD])
    annotation class MenuSelection

    /**
     * Adapt the [menuItem] or return null if the item is unsupported.
     */
    @MenuSelection
    fun adaptMenuItem(menuItem: MenuItem): Int? {
        return when (menuItem.itemId) {
            android.R.id.home -> TODO()
            R.id.action_back -> BACK
            R.id.action_forward -> FORWARD
            R.id.action_new_incognito_window -> NEW_INCOGNITO_WINDOW
            R.id.action_share -> SHARE
            R.id.action_copy -> COPY_LINK
            R.id.action_settings -> SETTINGS
            R.id.action_history -> OPEN_HISTORY
            R.id.action_downloads -> OPEN_DOWNLOADS
            R.id.action_resources -> OPEN_RESOURCES
            R.id.action_add_bookmark -> ADD_BOOKMARK
            R.id.action_find -> FIND
            else -> null
        }
    }

}
